#!/usr/bin/env python3
#-*- coding:utf-8 -*-

__author__ = "tongzi"

from xml.parsers.expat import ParserCreate

class DefaultSaxHandler(object):
	def start_element(self,name,attrs):
		print("sax start_element: %s, attrs: %s" % (name,str(attrs)))
		
	def end_element(self,name):
		print('sax:end_element: %s' % name)
	
	def char_data(self,text):
		print('sax: char_data: %s' % text)
		

xml = r'''<?xml version="1.0"?>
<ol>
	<li><a href="/python">python</a></li>
	<li><a href="/ruby">ruby</a></li>
</ol>
'''

handler = DefaultSaxHandler()
parser = ParserCreate()
#parser.return_unicode = True
parser.StartElementHandler = handler.start_element
parser.EndElementHandler = handler.end_element
parser.CharacterDataHandler = handler.char_data
parser.Parse(xml)	